<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlrecharclass - Perl Regular Expression Character Classes - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlrecharclass">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlrecharclass.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlrecharclass">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlrecharclass">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlrecharclass">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlrecharclass">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlrecharclass">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlrecharclass">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlrecharclass">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlrecharclass">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlrecharclass">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlrecharclass">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlrecharclass">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlrecharclass">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlrecharclass">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlrecharclass">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlrecharclass">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlrecharclass">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlrecharclass">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlrecharclass">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlrecharclass">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlrecharclass">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlrecharclass">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlrecharclass">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlrecharclass">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlrecharclass">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlrecharclass">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlrecharclass">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlrecharclass">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlrecharclass">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlrecharclass">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlrecharclass">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlrecharclass">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlrecharclass">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlrecharclass">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlrecharclass">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlrecharclass">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlrecharclass">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlrecharclass">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlrecharclass">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlrecharclass">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlrecharclass">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlrecharclass">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlrecharclass">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlrecharclass">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlrecharclass">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlrecharclass">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlrecharclass">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlrecharclass">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlrecharclass">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlrecharclass">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlrecharclass">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlrecharclass">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlrecharclass">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlrecharclass">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlrecharclass">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlrecharclass">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlrecharclass">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlrecharclass">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlrecharclass">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlrecharclass">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlrecharclass">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlrecharclass">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlrecharclass">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlrecharclass">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlrecharclass">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlrecharclass">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlrecharclass">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlrecharclass">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlrecharclass">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlrecharclass">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlrecharclass">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlrecharclass">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlrecharclass">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlrecharclass">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlrecharclass">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlrecharclass">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlrecharclass">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlrecharclass">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlrecharclass">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlrecharclass">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlrecharclass">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlrecharclass.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlrecharclass">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlrecharclass">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlrecharclass">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlrecharclass">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlrecharclass">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlrecharclass">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlrecharclass">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlrecharclass">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlrecharclass">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlrecharclass">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlrecharclass">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlrecharclass">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlrecharclass">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlrecharclass">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlrecharclass">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlrecharclass">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlrecharclass">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlrecharclass">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlrecharclass">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlrecharclass">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlrecharclass">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlrecharclass">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlrecharclass">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlrecharclass">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlrecharclass">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlrecharclass">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlrecharclass">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlrecharclass">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlrecharclass">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlrecharclass">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlrecharclass">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlrecharclass">5.35.1</a>
          <a class="dropdown-item active" href="perlrecharclass.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlrecharclass.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlrecharclass.html">perlrecharclass</a>
          <div id="more">
            (<a href="perlrecharclass.txt">source</a>,
            <a href="https://metacpan.org/pod/perlrecharclass">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#NAME">NAME </a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#The-dot">The dot</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Backslash-sequences">Backslash sequences               </a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#%5CN">\N</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Digits">Digits</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Word-characters">Word characters</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Whitespace">Whitespace</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Unicode-Properties">Unicode Properties</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Examples">Examples</a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Bracketed-Character-Classes">Bracketed Character Classes</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Special-Characters-Inside-a-Bracketed-Character-Class">Special Characters Inside a Bracketed Character Class</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Bracketed-Character-Classes-and-the-/xx-pattern-modifier">Bracketed Character Classes and the /xx pattern modifier</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Character-Ranges">Character Ranges</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Negation">Negation</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Backslash-Sequences">Backslash Sequences</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#POSIX-Character-Classes">POSIX Character Classes                 </a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Negation-of-POSIX-character-classes">Negation of POSIX character classes </a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#%5B=-=%5D-and-%5B.-.%5D">[= =] and [. .]</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Examples1">Examples</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlrecharclass.html#Extended-Bracketed-Character-Classes">Extended Bracketed Character Classes  </a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlrecharclass.html#NAME">#</a>NAME </h1>

<p>perlrecharclass - Perl Regular Expression Character Classes</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlrecharclass.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The top level documentation about Perl regular expressions is found in <a href="perlre.html">perlre</a>.</p>

<p>This manual page discusses the syntax and use of character classes in Perl regular expressions.</p>

<p>A character class is a way of denoting a set of characters in such a way that one character of the set is matched. It&#39;s important to remember that: matching a character class consumes exactly one character in the source string. (The source string is the string the regular expression is matched against.)</p>

<p>There are three types of character classes in Perl regular expressions: the dot, backslash sequences, and the form enclosed in square brackets. Keep in mind, though, that often the term &quot;character class&quot; is used to mean just the bracketed form. Certainly, most Perl documentation does that.</p>

<h2 id="The-dot"><a class="permalink" href="perlrecharclass.html#The-dot">#</a><a id="The"></a>The dot</h2>

<p>The dot (or period), <code>.</code> is probably the most used, and certainly the most well-known character class. By default, a dot matches any character, except for the newline. That default can be changed to add matching the newline by using the <i>single line</i> modifier: for the entire regular expression with the <code>/s</code> modifier, or locally with <code>(?s)</code> (and even globally within the scope of <a href="re.html#%27%2Fflags%27-mode"><code>use re &#39;/s&#39;</code></a>). (The <code><a href="perlrecharclass.html#%5CN">&quot;\N&quot;</a></code> backslash sequence, described below, matches any character except newline without regard to the <i>single line</i> modifier.)</p>

<p>Here are some examples:</p>

<pre><code class="plaintext">&quot;a&quot;  =~  /./       # Match
&quot;.&quot;  =~  /./       # Match
&quot;&quot;   =~  /./       # No match (dot has to match a character)
&quot;\n&quot; =~  /./       # No match (dot does not match a newline)
&quot;\n&quot; =~  /./s      # Match (global &#39;single line&#39; modifier)
&quot;\n&quot; =~  /(?s:.)/  # Match (local &#39;single line&#39; modifier)
&quot;ab&quot; =~  /^.$/     # No match (dot matches one character)</code></pre>

<h2 id="Backslash-sequences"><a class="permalink" href="perlrecharclass.html#Backslash-sequences">#</a><a id="Backslash"></a>Backslash sequences               </h2>

<p>A backslash sequence is a sequence of characters, the first one of which is a backslash. Perl ascribes special meaning to many such sequences, and some of these are character classes. That is, they match a single character each, provided that the character belongs to the specific set of characters defined by the sequence.</p>

<p>Here&#39;s a list of the backslash sequences that are character classes. They are discussed in more detail below. (For the backslash sequences that aren&#39;t character classes, see <a href="perlrebackslash.html">perlrebackslash</a>.)</p>

<pre><code class="plaintext">\d             Match a decimal digit character.
\D             Match a non-decimal-digit character.
\w             Match a &quot;word&quot; character.
\W             Match a non-&quot;word&quot; character.
\s             Match a whitespace character.
\S             Match a non-whitespace character.
\h             Match a horizontal whitespace character.
\H             Match a character that isn&#39;t horizontal whitespace.
\v             Match a vertical whitespace character.
\V             Match a character that isn&#39;t vertical whitespace.
\N             Match a character that isn&#39;t a newline.
\pP, \p{Prop}  Match a character that has the given Unicode property.
\PP, \P{Prop}  Match a character that doesn&#39;t have the Unicode property</code></pre>

<h3 id="\N"><a class="permalink" href="perlrecharclass.html#%5CN">#</a><a id="N"></a>\N</h3>

<p><code>\N</code>, available starting in v5.12, like the dot, matches any character that is not a newline. The difference is that <code>\N</code> is not influenced by the <i>single line</i> regular expression modifier (see <a href="perlrecharclass.html#The-dot">&quot;The dot&quot;</a> above). Note that the form <code>\N{...}</code> may mean something completely different. When the <code>{...}</code> is a <a href="perlre.html#Quantifiers">quantifier</a>, it means to match a non-newline character that many times. For example, <code>\N{3}</code> means to match 3 non-newlines; <code>\N{5,}</code> means to match 5 or more non-newlines. But if <code>{...}</code> is not a legal quantifier, it is presumed to be a named character. See <a href="charnames.html">charnames</a> for those. For example, none of <code>\N{COLON}</code>, <code>\N{4F}</code>, and <code>\N{F4}</code> contain legal quantifiers, so Perl will try to find characters whose names are respectively <code>COLON</code>, <code>4F</code>, and <code>F4</code>.</p>

<h3 id="Digits"><a class="permalink" href="perlrecharclass.html#Digits">#</a>Digits</h3>

<p><code>\d</code> matches a single character considered to be a decimal <i>digit</i>. If the <code>/a</code> regular expression modifier is in effect, it matches [0-9]. Otherwise, it matches anything that is matched by <code>\p{Digit}</code>, which includes [0-9]. (An unlikely possible exception is that under locale matching rules, the current locale might not have <code>[0-9]</code> matched by <code>\d</code>, and/or might match other characters whose code point is less than 256. The only such locale definitions that are legal would be to match <code>[0-9]</code> plus another set of 10 consecutive digit characters; anything else would be in violation of the C language standard, but Perl doesn&#39;t currently assume anything in regard to this.)</p>

<p>What this means is that unless the <code>/a</code> modifier is in effect <code>\d</code> not only matches the digits &#39;0&#39; - &#39;9&#39;, but also Arabic, Devanagari, and digits from other languages. This may cause some confusion, and some security issues.</p>

<p>Some digits that <code>\d</code> matches look like some of the [0-9] ones, but have different values. For example, BENGALI DIGIT FOUR (U+09EA) looks very much like an ASCII DIGIT EIGHT (U+0038), and LEPCHA DIGIT SIX (U+1C46) looks very much like an ASCII DIGIT FIVE (U+0035). An application that is expecting only the ASCII digits might be misled, or if the match is <code>\d+</code>, the matched string might contain a mixture of digits from different writing systems that look like they signify a number different than they actually do. <a href="./Unicode::UCD.html#num%28%29">&quot;num()&quot; in Unicode::UCD</a> can be used to safely calculate the value, returning <code>undef</code> if the input string contains such a mixture. Otherwise, for example, a displayed price might be deliberately different than it appears.</p>

<p>What <code>\p{Digit}</code> means (and hence <code>\d</code> except under the <code>/a</code> modifier) is <code>\p{General_Category=Decimal_Number}</code>, or synonymously, <code>\p{General_Category=Digit}</code>. Starting with Unicode version 4.1, this is the same set of characters matched by <code>\p{Numeric_Type=Decimal}</code>. But Unicode also has a different property with a similar name, <code>\p{Numeric_Type=Digit}</code>, which matches a completely different set of characters. These characters are things such as <code>CIRCLED DIGIT ONE</code> or subscripts, or are from writing systems that lack all ten digits.</p>

<p>The design intent is for <code>\d</code> to exactly match the set of characters that can safely be used with &quot;normal&quot; big-endian positional decimal syntax, where, for example 123 means one &#39;hundred&#39;, plus two &#39;tens&#39;, plus three &#39;ones&#39;. This positional notation does not necessarily apply to characters that match the other type of &quot;digit&quot;, <code>\p{Numeric_Type=Digit}</code>, and so <code>\d</code> doesn&#39;t match them.</p>

<p>The Tamil digits (U+0BE6 - U+0BEF) can also legally be used in old-style Tamil numbers in which they would appear no more than one in a row, separated by characters that mean &quot;times 10&quot;, &quot;times 100&quot;, etc. (See <a href="https://www.unicode.org/notes/tn21">https://www.unicode.org/notes/tn21</a>.)</p>

<p>Any character not matched by <code>\d</code> is matched by <code>\D</code>.</p>

<h3 id="Word-characters"><a class="permalink" href="perlrecharclass.html#Word-characters">#</a><a id="Word"></a>Word characters</h3>

<p>A <code>\w</code> matches a single alphanumeric character (an alphabetic character, or a decimal digit); or a connecting punctuation character, such as an underscore (&quot;_&quot;); or a &quot;mark&quot; character (like some sort of accent) that attaches to one of those. It does not match a whole word. To match a whole word, use <code>\w+</code>. This isn&#39;t the same thing as matching an English word, but in the ASCII range it is the same as a string of Perl-identifier characters.</p>

<dl>

<dt id="If-the-/a-modifier-is-in-effect-..."><a class="permalink" href="perlrecharclass.html#If-the-/a-modifier-is-in-effect-...">#</a><a id="If"></a><a id="If-the-a-modifier-is-in-effect"></a>If the <code>/a</code> modifier is in effect ...</dt>
<dd>

<p><code>\w</code> matches the 63 characters [a-zA-Z0-9_].</p>

</dd>
<dt id="otherwise-..."><a class="permalink" href="perlrecharclass.html#otherwise-...">#</a><a id="otherwise"></a>otherwise ...</dt>
<dd>

<dl>

<dt id="For-code-points-above-255-..."><a class="permalink" href="perlrecharclass.html#For-code-points-above-255-...">#</a><a id="For"></a><a id="For-code-points-above-255"></a>For code points above 255 ...</dt>
<dd>

<p><code>\w</code> matches the same as <code>\p{Word}</code> matches in this range. That is, it matches Thai letters, Greek letters, etc. This includes connector punctuation (like the underscore) which connect two words together, or diacritics, such as a <code>COMBINING TILDE</code> and the modifier letters, which are generally used to add auxiliary markings to letters.</p>

</dd>
<dt id="For-code-points-below-256-..."><a class="permalink" href="perlrecharclass.html#For-code-points-below-256-...">#</a><a id="For1"></a><a id="For-code-points-below-256"></a>For code points below 256 ...</dt>
<dd>

<dl>

<dt id="if-locale-rules-are-in-effect-..."><a class="permalink" href="perlrecharclass.html#if-locale-rules-are-in-effect-...">#</a><a id="if"></a><a id="if-locale-rules-are-in-effect"></a>if locale rules are in effect ...</dt>
<dd>

<p><code>\w</code> matches the platform&#39;s native underscore character plus whatever the locale considers to be alphanumeric.</p>

</dd>
<dt id="if,-instead,-Unicode-rules-are-in-effect-..."><a class="permalink" href="perlrecharclass.html#if,-instead,-Unicode-rules-are-in-effect-...">#</a><a id="if1"></a><a id="if-instead-Unicode-rules-are-in-effect"></a>if, instead, Unicode rules are in effect ...</dt>
<dd>

<p><code>\w</code> matches exactly what <code>\p{Word}</code> matches.</p>

</dd>
<dt id="otherwise-...1"><a class="permalink" href="perlrecharclass.html#otherwise-...1">#</a><a id="otherwise1"></a>otherwise ...</dt>
<dd>

<p><code>\w</code> matches [a-zA-Z0-9_].</p>

</dd>
</dl>

</dd>
</dl>

</dd>
</dl>

<p>Which rules apply are determined as described in <a href="perlre.html#Which-character-set-modifier-is-in-effect%3F">&quot;Which character set modifier is in effect?&quot; in perlre</a>.</p>

<p>There are a number of security issues with the full Unicode list of word characters. See <a href="http://unicode.org/reports/tr36">http://unicode.org/reports/tr36</a>.</p>

<p>Also, for a somewhat finer-grained set of characters that are in programming language identifiers beyond the ASCII range, you may wish to instead use the more customized <a href="perlrecharclass.html#Unicode-Properties">&quot;Unicode Properties&quot;</a>, <code>\p{ID_Start}</code>, <code>\p{ID_Continue}</code>, <code>\p{XID_Start}</code>, and <code>\p{XID_Continue}</code>. See <a href="http://unicode.org/reports/tr31">http://unicode.org/reports/tr31</a>.</p>

<p>Any character not matched by <code>\w</code> is matched by <code>\W</code>.</p>

<h3 id="Whitespace"><a class="permalink" href="perlrecharclass.html#Whitespace">#</a>Whitespace</h3>

<p><code>\s</code> matches any single character considered whitespace.</p>

<dl>

<dt id="If-the-/a-modifier-is-in-effect-...1"><a class="permalink" href="perlrecharclass.html#If-the-/a-modifier-is-in-effect-...1">#</a><a id="If1"></a><a id="If-the-a-modifier-is-in-effect1"></a>If the <code>/a</code> modifier is in effect ...</dt>
<dd>

<p>In all Perl versions, <code>\s</code> matches the 5 characters [\t\n\f\r ]; that is, the horizontal tab, the newline, the form feed, the carriage return, and the space. Starting in Perl v5.18, it also matches the vertical tab, <code>\cK</code>. See note <code>[1]</code> below for a discussion of this.</p>

</dd>
<dt id="otherwise-...2"><a class="permalink" href="perlrecharclass.html#otherwise-...2">#</a><a id="otherwise2"></a>otherwise ...</dt>
<dd>

<dl>

<dt id="For-code-points-above-255-...1"><a class="permalink" href="perlrecharclass.html#For-code-points-above-255-...1">#</a><a id="For2"></a><a id="For-code-points-above-2551"></a>For code points above 255 ...</dt>
<dd>

<p><code>\s</code> matches exactly the code points above 255 shown with an &quot;s&quot; column in the table below.</p>

</dd>
<dt id="For-code-points-below-256-...1"><a class="permalink" href="perlrecharclass.html#For-code-points-below-256-...1">#</a><a id="For3"></a><a id="For-code-points-below-2561"></a>For code points below 256 ...</dt>
<dd>

<dl>

<dt id="if-locale-rules-are-in-effect-...1"><a class="permalink" href="perlrecharclass.html#if-locale-rules-are-in-effect-...1">#</a><a id="if2"></a><a id="if-locale-rules-are-in-effect1"></a>if locale rules are in effect ...</dt>
<dd>

<p><code>\s</code> matches whatever the locale considers to be whitespace.</p>

</dd>
<dt id="if,-instead,-Unicode-rules-are-in-effect-...1"><a class="permalink" href="perlrecharclass.html#if,-instead,-Unicode-rules-are-in-effect-...1">#</a><a id="if3"></a><a id="if-instead-Unicode-rules-are-in-effect1"></a>if, instead, Unicode rules are in effect ...</dt>
<dd>

<p><code>\s</code> matches exactly the characters shown with an &quot;s&quot; column in the table below.</p>

</dd>
<dt id="otherwise-...3"><a class="permalink" href="perlrecharclass.html#otherwise-...3">#</a><a id="otherwise3"></a>otherwise ...</dt>
<dd>

<p><code>\s</code> matches [\t\n\f\r ] and, starting in Perl v5.18, the vertical tab, <code>\cK</code>. (See note <code>[1]</code> below for a discussion of this.) Note that this list doesn&#39;t include the non-breaking space.</p>

</dd>
</dl>

</dd>
</dl>

</dd>
</dl>

<p>Which rules apply are determined as described in <a href="perlre.html#Which-character-set-modifier-is-in-effect%3F">&quot;Which character set modifier is in effect?&quot; in perlre</a>.</p>

<p>Any character not matched by <code>\s</code> is matched by <code>\S</code>.</p>

<p><code>\h</code> matches any character considered horizontal whitespace; this includes the platform&#39;s space and tab characters and several others listed in the table below. <code>\H</code> matches any character not considered horizontal whitespace. They use the platform&#39;s native character set, and do not consider any locale that may otherwise be in use.</p>

<p><code>\v</code> matches any character considered vertical whitespace; this includes the platform&#39;s carriage return and line feed characters (newline) plus several other characters, all listed in the table below. <code>\V</code> matches any character not considered vertical whitespace. They use the platform&#39;s native character set, and do not consider any locale that may otherwise be in use.</p>

<p><code>\R</code> matches anything that can be considered a newline under Unicode rules. It can match a multi-character sequence. It cannot be used inside a bracketed character class; use <code>\v</code> instead (vertical whitespace). It uses the platform&#39;s native character set, and does not consider any locale that may otherwise be in use. Details are discussed in <a href="perlrebackslash.html">perlrebackslash</a>.</p>

<p>Note that unlike <code>\s</code> (and <code>\d</code> and <code>\w</code>), <code>\h</code> and <code>\v</code> always match the same characters, without regard to other factors, such as the active locale or whether the source string is in UTF-8 format.</p>

<p>One might think that <code>\s</code> is equivalent to <code>[\h\v]</code>. This is indeed true starting in Perl v5.18, but prior to that, the sole difference was that the vertical tab (<code>&quot;\cK&quot;</code>) was not matched by <code>\s</code>.</p>

<p>The following table is a complete listing of characters matched by <code>\s</code>, <code>\h</code> and <code>\v</code> as of Unicode 6.3.</p>

<p>The first column gives the Unicode code point of the character (in hex format), the second column gives the (Unicode) name. The third column indicates by which class(es) the character is matched (assuming no locale is in effect that changes the <code>\s</code> matching).</p>

<pre><code class="plaintext">0x0009        CHARACTER TABULATION   h s
0x000a              LINE FEED (LF)    vs
0x000b             LINE TABULATION    vs  [1]
0x000c              FORM FEED (FF)    vs
0x000d        CARRIAGE RETURN (CR)    vs
0x0020                       SPACE   h s
0x0085             NEXT LINE (NEL)    vs  [2]
0x00a0              NO-BREAK SPACE   h s  [2]
0x1680            OGHAM SPACE MARK   h s
0x2000                     EN QUAD   h s
0x2001                     EM QUAD   h s
0x2002                    EN SPACE   h s
0x2003                    EM SPACE   h s
0x2004          THREE-PER-EM SPACE   h s
0x2005           FOUR-PER-EM SPACE   h s
0x2006            SIX-PER-EM SPACE   h s
0x2007                FIGURE SPACE   h s
0x2008           PUNCTUATION SPACE   h s
0x2009                  THIN SPACE   h s
0x200a                  HAIR SPACE   h s
0x2028              LINE SEPARATOR    vs
0x2029         PARAGRAPH SEPARATOR    vs
0x202f       NARROW NO-BREAK SPACE   h s
0x205f   MEDIUM MATHEMATICAL SPACE   h s
0x3000           IDEOGRAPHIC SPACE   h s</code></pre>

<dl>

<dt id="[1]"><a class="permalink" href="perlrecharclass.html#%5B1%5D">#</a><a id="pod-1"></a>[1]</dt>
<dd>

<p>Prior to Perl v5.18, <code>\s</code> did not match the vertical tab. <code>[^\S\cK]</code> (obscurely) matches what <code>\s</code> traditionally did.</p>

</dd>
<dt id="[2]"><a class="permalink" href="perlrecharclass.html#%5B2%5D">#</a><a id="pod-2"></a>[2]</dt>
<dd>

<p>NEXT LINE and NO-BREAK SPACE may or may not match <code>\s</code> depending on the rules in effect. See <a href="perlrecharclass.html#Whitespace">the beginning of this section</a>.</p>

</dd>
</dl>

<h3 id="Unicode-Properties"><a class="permalink" href="perlrecharclass.html#Unicode-Properties">#</a><a id="Unicode"></a>Unicode Properties</h3>

<p><code>\pP</code> and <code>\p{Prop}</code> are character classes to match characters that fit given Unicode properties. One letter property names can be used in the <code>\pP</code> form, with the property name following the <code>\p</code>, otherwise, braces are required. When using braces, there is a single form, which is just the property name enclosed in the braces, and a compound form which looks like <code>\p{name=value}</code>, which means to match if the property &quot;name&quot; for the character has that particular &quot;value&quot;. For instance, a match for a number can be written as <code>/\pN/</code> or as <code>/\p{Number}/</code>, or as <code>/\p{Number=True}/</code>. Lowercase letters are matched by the property <i>Lowercase_Letter</i> which has the short form <i>Ll</i>. They need the braces, so are written as <code>/\p{Ll}/</code> or <code>/\p{Lowercase_Letter}/</code>, or <code>/\p{General_Category=Lowercase_Letter}/</code> (the underscores are optional). <code>/\pLl/</code> is valid, but means something different. It matches a two character string: a letter (Unicode property <code>\pL</code>), followed by a lowercase <code>l</code>.</p>

<p>What a Unicode property matches is never subject to locale rules, and if locale rules are not otherwise in effect, the use of a Unicode property will force the regular expression into using Unicode rules, if it isn&#39;t already.</p>

<p>Note that almost all properties are immune to case-insensitive matching. That is, adding a <code>/i</code> regular expression modifier does not change what they match. But there are two sets that are affected. The first set is <code>Uppercase_Letter</code>, <code>Lowercase_Letter</code>, and <code>Titlecase_Letter</code>, all of which match <code>Cased_Letter</code> under <code>/i</code> matching. The second set is <code>Uppercase</code>, <code>Lowercase</code>, and <code>Titlecase</code>, all of which match <code>Cased</code> under <code>/i</code> matching. (The difference between these sets is that some things, such as Roman numerals, come in both upper and lower case, so they are <code>Cased</code>, but aren&#39;t considered to be letters, so they aren&#39;t <code>Cased_Letter</code>s. They&#39;re actually <code>Letter_Number</code>s.) This set also includes its subsets <code>PosixUpper</code> and <code>PosixLower</code>, both of which under <code>/i</code> match <code>PosixAlpha</code>.</p>

<p>For more details on Unicode properties, see <a href="perlunicode.html#Unicode-Character-Properties">&quot;Unicode Character Properties&quot; in perlunicode</a>; for a complete list of possible properties, see <a href="perluniprops.html#Properties-accessible-through-%5Cp%7B%7D-and-%5CP%7B%7D">&quot;Properties accessible through \p{} and \P{}&quot; in perluniprops</a>, which notes all forms that have <code>/i</code> differences. It is also possible to define your own properties. This is discussed in <a href="perlunicode.html#User-Defined-Character-Properties">&quot;User-Defined Character Properties&quot; in perlunicode</a>.</p>

<p>Unicode properties are defined (surprise!) only on Unicode code points. Starting in v5.20, when matching against <code>\p</code> and <code>\P</code>, Perl treats non-Unicode code points (those above the legal Unicode maximum of 0x10FFFF) as if they were typical unassigned Unicode code points.</p>

<p>Prior to v5.20, Perl raised a warning and made all matches fail on non-Unicode code points. This could be somewhat surprising:</p>

<pre><code class="plaintext">chr(0x110000) =~ \p{ASCII_Hex_Digit=True}     # Fails on Perls &lt; v5.20.
chr(0x110000) =~ \p{ASCII_Hex_Digit=False}    # Also fails on Perls
                                              # &lt; v5.20</code></pre>

<p>Even though these two matches might be thought of as complements, until v5.20 they were so only on Unicode code points.</p>

<p>Starting in perl v5.30, wildcards are allowed in Unicode property values. See <a href="perlunicode.html#Wildcards-in-Property-Values">&quot;Wildcards in Property Values&quot; in perlunicode</a>.</p>

<h4 id="Examples"><a class="permalink" href="perlrecharclass.html#Examples">#</a>Examples</h4>

<pre><code class="plaintext">&quot;a&quot;  =~  /\w/      # Match, &quot;a&quot; is a &#39;word&#39; character.
&quot;7&quot;  =~  /\w/      # Match, &quot;7&quot; is a &#39;word&#39; character as well.
&quot;a&quot;  =~  /\d/      # No match, &quot;a&quot; isn&#39;t a digit.
&quot;7&quot;  =~  /\d/      # Match, &quot;7&quot; is a digit.
&quot; &quot;  =~  /\s/      # Match, a space is whitespace.
&quot;a&quot;  =~  /\D/      # Match, &quot;a&quot; is a non-digit.
&quot;7&quot;  =~  /\D/      # No match, &quot;7&quot; is not a non-digit.
&quot; &quot;  =~  /\S/      # No match, a space is not non-whitespace.

&quot; &quot;  =~  /\h/      # Match, space is horizontal whitespace.
&quot; &quot;  =~  /\v/      # No match, space is not vertical whitespace.
&quot;\r&quot; =~  /\v/      # Match, a return is vertical whitespace.

&quot;a&quot;  =~  /\pL/     # Match, &quot;a&quot; is a letter.
&quot;a&quot;  =~  /\p{Lu}/  # No match, /\p{Lu}/ matches upper case letters.

&quot;\x{0e0b}&quot; =~ /\p{Thai}/  # Match, \x{0e0b} is the character
                          # &#39;THAI CHARACTER SO SO&#39;, and that&#39;s in
                          # Thai Unicode class.
&quot;a&quot;  =~  /\P{Lao}/ # Match, as &quot;a&quot; is not a Laotian character.</code></pre>

<p>It is worth emphasizing that <code>\d</code>, <code>\w</code>, etc, match single characters, not complete numbers or words. To match a number (that consists of digits), use <code>\d+</code>; to match a word, use <code>\w+</code>. But be aware of the security considerations in doing so, as mentioned above.</p>

<h2 id="Bracketed-Character-Classes"><a class="permalink" href="perlrecharclass.html#Bracketed-Character-Classes">#</a><a id="Bracketed"></a>Bracketed Character Classes</h2>

<p>The third form of character class you can use in Perl regular expressions is the bracketed character class. In its simplest form, it lists the characters that may be matched, surrounded by square brackets, like this: <code>[aeiou]</code>. This matches one of <code>a</code>, <code>e</code>, <code>i</code>, <code>o</code> or <code>u</code>. Like the other character classes, exactly one character is matched.* To match a longer string consisting of characters mentioned in the character class, follow the character class with a <a href="perlre.html#Quantifiers">quantifier</a>. For instance, <code>[aeiou]+</code> matches one or more lowercase English vowels.</p>

<p>Repeating a character in a character class has no effect; it&#39;s considered to be in the set only once.</p>

<p>Examples:</p>

<pre><code class="plaintext">&quot;e&quot;  =~  /[aeiou]/        # Match, as &quot;e&quot; is listed in the class.
&quot;p&quot;  =~  /[aeiou]/        # No match, &quot;p&quot; is not listed in the class.
&quot;ae&quot; =~  /^[aeiou]$/      # No match, a character class only matches
                          # a single character.
&quot;ae&quot; =~  /^[aeiou]+$/     # Match, due to the quantifier.

-------</code></pre>

<p>* There are two exceptions to a bracketed character class matching a single character only. Each requires special handling by Perl to make things work:</p>

<ul>

<li><p>When the class is to match caselessly under <code>/i</code> matching rules, and a character that is explicitly mentioned inside the class matches a multiple-character sequence caselessly under Unicode rules, the class will also match that sequence. For example, Unicode says that the letter <code>LATIN SMALL LETTER SHARP S</code> should match the sequence <code>ss</code> under <code>/i</code> rules. Thus,</p>

<pre><code class="plaintext">&#39;ss&#39; =~ /\A\N{LATIN SMALL LETTER SHARP S}\z/i             # Matches
&#39;ss&#39; =~ /\A[aeioust\N{LATIN SMALL LETTER SHARP S}]\z/i    # Matches</code></pre>

<p>For this to happen, the class must not be inverted (see <a href="perlrecharclass.html#Negation">&quot;Negation&quot;</a>) and the character must be explicitly specified, and not be part of a multi-character range (not even as one of its endpoints). (<a href="perlrecharclass.html#Character-Ranges">&quot;Character Ranges&quot;</a> will be explained shortly.) Therefore,</p>

<pre><code class="plaintext">&#39;ss&#39; =~ /\A[\0-\x{ff}]\z/ui       # Doesn&#39;t match
&#39;ss&#39; =~ /\A[\0-\N{LATIN SMALL LETTER SHARP S}]\z/ui   # No match
&#39;ss&#39; =~ /\A[\xDF-\xDF]\z/ui   # Matches on ASCII platforms, since
                              # \xDF is LATIN SMALL LETTER SHARP S,
                              # and the range is just a single
                              # element</code></pre>

<p>Note that it isn&#39;t a good idea to specify these types of ranges anyway.</p>

</li>
<li><p>Some names known to <code>\N{...}</code> refer to a sequence of multiple characters, instead of the usual single character. When one of these is included in the class, the entire sequence is matched. For example,</p>

<pre><code>&quot;\N{TAMIL LETTER KA}\N{TAMIL VOWEL SIGN AU}&quot;
                            =~ / ^ [\N{TAMIL SYLLABLE KAU}]  $ /x;</code></pre>

<p>matches, because <code>\N{TAMIL SYLLABLE KAU}</code> is a named sequence consisting of the two characters matched against. Like the other instance where a bracketed class can match multiple characters, and for similar reasons, the class must not be inverted, and the named sequence may not appear in a range, even one where it is both endpoints. If these happen, it is a fatal error if the character class is within the scope of <a href="re.html#%27strict%27-mode"><code>use re &#39;strict</code></a>, or within an extended <a href="perlrecharclass.html#Extended-Bracketed-Character-Classes"><code>(?[...])</code></a> class; otherwise only the first code point is used (with a <code>regexp</code>-type warning raised).</p>

</li>
</ul>

<h3 id="Special-Characters-Inside-a-Bracketed-Character-Class"><a class="permalink" href="perlrecharclass.html#Special-Characters-Inside-a-Bracketed-Character-Class">#</a><a id="Special"></a>Special Characters Inside a Bracketed Character Class</h3>

<p>Most characters that are meta characters in regular expressions (that is, characters that carry a special meaning like <code>.</code>, <code>*</code>, or <code>(</code>) lose their special meaning and can be used inside a character class without the need to escape them. For instance, <code>[()]</code> matches either an opening parenthesis, or a closing parenthesis, and the parens inside the character class don&#39;t group or capture. Be aware that, unless the pattern is evaluated in single-quotish context, variable interpolation will take place before the bracketed class is parsed:</p>

<pre><code>$, = &quot;\t| &quot;;
$a =~ m&#39;[$,]&#39;;        # single-quotish: matches &#39;$&#39; or &#39;,&#39;
$a =~ q{[$,]}&#39;        # same
$a =~ m/[$,]/;        # double-quotish: Because we made an
                      #   assignment to $, above, this now
                      #   matches &quot;\t&quot;, &quot;|&quot;, or &quot; &quot;</code></pre>

<p>Characters that may carry a special meaning inside a character class are: <code>\</code>, <code>^</code>, <code>-</code>, <code>[</code> and <code>]</code>, and are discussed below. They can be escaped with a backslash, although this is sometimes not needed, in which case the backslash may be omitted.</p>

<p>The sequence <code>\b</code> is special inside a bracketed character class. While outside the character class, <code>\b</code> is an assertion indicating a point that does not have either two word characters or two non-word characters on either side, inside a bracketed character class, <code>\b</code> matches a backspace character.</p>

<p>The sequences <code>\a</code>, <code>\c</code>, <code>\e</code>, <code>\f</code>, <code>\n</code>, <code>\N{<i>NAME</i>}</code>, <code>\N{U+<i>hex char</i>}</code>, <code>\r</code>, <code>\t</code>, and <code>\x</code> are also special and have the same meanings as they do outside a bracketed character class.</p>

<p>Also, a backslash followed by two or three octal digits is considered an octal number.</p>

<p>A <code>[</code> is not special inside a character class, unless it&#39;s the start of a POSIX character class (see <a href="perlrecharclass.html#POSIX-Character-Classes">&quot;POSIX Character Classes&quot;</a> below). It normally does not need escaping.</p>

<p>A <code>]</code> is normally either the end of a POSIX character class (see <a href="perlrecharclass.html#POSIX-Character-Classes">&quot;POSIX Character Classes&quot;</a> below), or it signals the end of the bracketed character class. If you want to include a <code>]</code> in the set of characters, you must generally escape it.</p>

<p>However, if the <code>]</code> is the <i>first</i> (or the second if the first character is a caret) character of a bracketed character class, it does not denote the end of the class (as you cannot have an empty class) and is considered part of the set of characters that can be matched without escaping.</p>

<p>Examples:</p>

<pre><code class="plaintext">&quot;+&quot;   =~ /[+?*]/     #  Match, &quot;+&quot; in a character class is not special.
&quot;\cH&quot; =~ /[\b]/      #  Match, \b inside in a character class
                     #  is equivalent to a backspace.
&quot;]&quot;   =~ /[][]/      #  Match, as the character class contains
                     #  both [ and ].
&quot;[]&quot;  =~ /[[]]/      #  Match, the pattern contains a character class
                     #  containing just [, and the character class is
                     #  followed by a ].</code></pre>

<h3 id="Bracketed-Character-Classes-and-the-/xx-pattern-modifier"><a class="permalink" href="perlrecharclass.html#Bracketed-Character-Classes-and-the-/xx-pattern-modifier">#</a><a id="Bracketed1"></a><a id="Bracketed-Character-Classes-and-the-xx-pattern-modifier"></a>Bracketed Character Classes and the <code>/xx</code> pattern modifier</h3>

<p>Normally SPACE and TAB characters have no special meaning inside a bracketed character class; they are just added to the list of characters matched by the class. But if the <a href="perlre.html#%2Fx-and-%2Fxx"><code>/xx</code></a> pattern modifier is in effect, they are generally ignored and can be added to improve readability. They can&#39;t be added in the middle of a single construct:</p>

<pre><code class="plaintext">/ [ \x{10 FFFF} ] /xx  # WRONG!</code></pre>

<p>The SPACE in the middle of the hex constant is illegal.</p>

<p>To specify a literal SPACE character, you can escape it with a backslash, like:</p>

<pre><code class="plaintext">/[ a e i o u \  ]/xx</code></pre>

<p>This matches the English vowels plus the SPACE character.</p>

<p>For clarity, you should already have been using <code>\t</code> to specify a literal tab, and <code>\t</code> is unaffected by <code>/xx</code>.</p>

<h3 id="Character-Ranges"><a class="permalink" href="perlrecharclass.html#Character-Ranges">#</a><a id="Character"></a>Character Ranges</h3>

<p>It is not uncommon to want to match a range of characters. Luckily, instead of listing all characters in the range, one may use the hyphen (<code>-</code>). If inside a bracketed character class you have two characters separated by a hyphen, it&#39;s treated as if all characters between the two were in the class. For instance, <code>[0-9]</code> matches any ASCII digit, and <code>[a-m]</code> matches any lowercase letter from the first half of the ASCII alphabet.</p>

<p>Note that the two characters on either side of the hyphen are not necessarily both letters or both digits. Any character is possible, although not advisable. <code>[&#39;-?]</code> contains a range of characters, but most people will not know which characters that means. Furthermore, such ranges may lead to portability problems if the code has to run on a platform that uses a different character set, such as EBCDIC.</p>

<p>If a hyphen in a character class cannot syntactically be part of a range, for instance because it is the first or the last character of the character class, or if it immediately follows a range, the hyphen isn&#39;t special, and so is considered a character to be matched literally. If you want a hyphen in your set of characters to be matched and its position in the class is such that it could be considered part of a range, you must escape that hyphen with a backslash.</p>

<p>Examples:</p>

<pre><code class="plaintext">[a-z]       #  Matches a character that is a lower case ASCII letter.
[a-fz]      #  Matches any letter between &#39;a&#39; and &#39;f&#39; (inclusive) or
            #  the letter &#39;z&#39;.
[-z]        #  Matches either a hyphen (&#39;-&#39;) or the letter &#39;z&#39;.
[a-f-m]     #  Matches any letter between &#39;a&#39; and &#39;f&#39; (inclusive), the
            #  hyphen (&#39;-&#39;), or the letter &#39;m&#39;.
[&#39;-?]       #  Matches any of the characters  &#39;()*+,-./0123456789:;&lt;=&gt;?
            #  (But not on an EBCDIC platform).
[\N{APOSTROPHE}-\N{QUESTION MARK}]
            #  Matches any of the characters  &#39;()*+,-./0123456789:;&lt;=&gt;?
            #  even on an EBCDIC platform.
[\N{U+27}-\N{U+3F}] # Same. (U+27 is &quot;&#39;&quot;, and U+3F is &quot;?&quot;)</code></pre>

<p>As the final two examples above show, you can achieve portability to non-ASCII platforms by using the <code>\N{...}</code> form for the range endpoints. These indicate that the specified range is to be interpreted using Unicode values, so <code>[\N{U+27}-\N{U+3F}]</code> means to match <code>\N{U+27}</code>, <code>\N{U+28}</code>, <code>\N{U+29}</code>, ..., <code>\N{U+3D}</code>, <code>\N{U+3E}</code>, and <code>\N{U+3F}</code>, whatever the native code point versions for those are. These are called &quot;Unicode&quot; ranges. If either end is of the <code>\N{...}</code> form, the range is considered Unicode. A <code>regexp</code> warning is raised under <code><span style="white-space: nowrap;">&quot;use re &#39;strict&#39;&quot;</span></code> if the other endpoint is specified non-portably:</p>

<pre><code>[\N{U+00}-\x09]    # Warning under re &#39;strict&#39;; \x09 is non-portable
[\N{U+00}-\t]      # No warning;</code></pre>

<p>Both of the above match the characters <code>\N{U+00}</code> <code>\N{U+01}</code>, ... <code>\N{U+08}</code>, <code>\N{U+09}</code>, but the <code>\x09</code> looks like it could be a mistake so the warning is raised (under <code>re &#39;strict&#39;</code>) for it.</p>

<p>Perl also guarantees that the ranges <code>A-Z</code>, <code>a-z</code>, <code>0-9</code>, and any subranges of these match what an English-only speaker would expect them to match on any platform. That is, <code>[A-Z]</code> matches the 26 ASCII uppercase letters; <code>[a-z]</code> matches the 26 lowercase letters; and <code>[0-9]</code> matches the 10 digits. Subranges, like <code>[h-k]</code>, match correspondingly, in this case just the four letters <code>&quot;h&quot;</code>, <code>&quot;i&quot;</code>, <code>&quot;j&quot;</code>, and <code>&quot;k&quot;</code>. This is the natural behavior on ASCII platforms where the code points (ordinal values) for <code>&quot;h&quot;</code> through <code>&quot;k&quot;</code> are consecutive integers (0x68 through 0x6B). But special handling to achieve this may be needed on platforms with a non-ASCII native character set. For example, on EBCDIC platforms, the code point for <code>&quot;h&quot;</code> is 0x88, <code>&quot;i&quot;</code> is 0x89, <code>&quot;j&quot;</code> is 0x91, and <code>&quot;k&quot;</code> is 0x92. Perl specially treats <code>[h-k]</code> to exclude the seven code points in the gap: 0x8A through 0x90. This special handling is only invoked when the range is a subrange of one of the ASCII uppercase, lowercase, and digit ranges, AND each end of the range is expressed either as a literal, like <code>&quot;A&quot;</code>, or as a named character (<code>\N{...}</code>, including the <code>\N{U+...</code> form).</p>

<p>EBCDIC Examples:</p>

<pre><code class="plaintext">[i-j]               #  Matches either &quot;i&quot; or &quot;j&quot;
[i-\N{LATIN SMALL LETTER J}]  # Same
[i-\N{U+6A}]        #  Same
[\N{U+69}-\N{U+6A}] #  Same
[\x{89}-\x{91}]     #  Matches 0x89 (&quot;i&quot;), 0x8A .. 0x90, 0x91 (&quot;j&quot;)
[i-\x{91}]          #  Same
[\x{89}-j]          #  Same
[i-J]               #  Matches, 0x89 (&quot;i&quot;) .. 0xC1 (&quot;J&quot;); special
                    #  handling doesn&#39;t apply because range is mixed
                    #  case</code></pre>

<h3 id="Negation"><a class="permalink" href="perlrecharclass.html#Negation">#</a>Negation</h3>

<p>It is also possible to instead list the characters you do not want to match. You can do so by using a caret (<code>^</code>) as the first character in the character class. For instance, <code>[^a-z]</code> matches any character that is not a lowercase ASCII letter, which therefore includes more than a million Unicode code points. The class is said to be &quot;negated&quot; or &quot;inverted&quot;.</p>

<p>This syntax make the caret a special character inside a bracketed character class, but only if it is the first character of the class. So if you want the caret as one of the characters to match, either escape the caret or else don&#39;t list it first.</p>

<p>In inverted bracketed character classes, Perl ignores the Unicode rules that normally say that named sequence, and certain characters should match a sequence of multiple characters use under caseless <code>/i</code> matching. Following those rules could lead to highly confusing situations:</p>

<pre><code>&quot;ss&quot; =~ /^[^\xDF]+$/ui;   # Matches!</code></pre>

<p>This should match any sequences of characters that aren&#39;t <code>\xDF</code> nor what <code>\xDF</code> matches under <code>/i</code>. <code>&quot;s&quot;</code> isn&#39;t <code>\xDF</code>, but Unicode says that <code>&quot;ss&quot;</code> is what <code>\xDF</code> matches under <code>/i</code>. So which one &quot;wins&quot;? Do you fail the match because the string has <code>ss</code> or accept it because it has an <code>s</code> followed by another <code>s</code>? Perl has chosen the latter. (See note in <a href="perlrecharclass.html#Bracketed-Character-Classes">&quot;Bracketed Character Classes&quot;</a> above.)</p>

<p>Examples:</p>

<pre><code class="plaintext">&quot;e&quot;  =~  /[^aeiou]/   #  No match, the &#39;e&#39; is listed.
&quot;x&quot;  =~  /[^aeiou]/   #  Match, as &#39;x&#39; isn&#39;t a lowercase vowel.
&quot;^&quot;  =~  /[^^]/       #  No match, matches anything that isn&#39;t a caret.
&quot;^&quot;  =~  /[x^]/       #  Match, caret is not special here.</code></pre>

<h3 id="Backslash-Sequences"><a class="permalink" href="perlrecharclass.html#Backslash-Sequences">#</a><a id="Backslash1"></a>Backslash Sequences</h3>

<p>You can put any backslash sequence character class (with the exception of <code>\N</code> and <code>\R</code>) inside a bracketed character class, and it will act just as if you had put all characters matched by the backslash sequence inside the character class. For instance, <code>[a-f\d]</code> matches any decimal digit, or any of the lowercase letters between &#39;a&#39; and &#39;f&#39; inclusive.</p>

<p><code>\N</code> within a bracketed character class must be of the forms <code>\N{<i>name</i>}</code> or <code>\N{U+<i>hex char</i>}</code>, and NOT be the form that matches non-newlines, for the same reason that a dot <code>.</code> inside a bracketed character class loses its special meaning: it matches nearly anything, which generally isn&#39;t what you want to happen.</p>

<p>Examples:</p>

<pre><code class="plaintext">/[\p{Thai}\d]/     # Matches a character that is either a Thai
                   # character, or a digit.
/[^\p{Arabic}()]/  # Matches a character that is neither an Arabic
                   # character, nor a parenthesis.</code></pre>

<p>Backslash sequence character classes cannot form one of the endpoints of a range. Thus, you can&#39;t say:</p>

<pre><code class="plaintext">/[\p{Thai}-\d]/     # Wrong!</code></pre>

<h3 id="POSIX-Character-Classes"><a class="permalink" href="perlrecharclass.html#POSIX-Character-Classes">#</a><a id="POSIX"></a>POSIX Character Classes                 </h3>

<p>POSIX character classes have the form <code>[:class:]</code>, where <i>class</i> is the name, and the <code>[:</code> and <code>:]</code> delimiters. POSIX character classes only appear <i>inside</i> bracketed character classes, and are a convenient and descriptive way of listing a group of characters.</p>

<p>Be careful about the syntax,</p>

<pre><code># Correct:
$string =~ /[[:alpha:]]/

# Incorrect (will warn):
$string =~ /[:alpha:]/</code></pre>

<p>The latter pattern would be a character class consisting of a colon, and the letters <code>a</code>, <code>l</code>, <code>p</code> and <code>h</code>.</p>

<p>POSIX character classes can be part of a larger bracketed character class. For example,</p>

<pre><code class="plaintext">[01[:alpha:]%]</code></pre>

<p>is valid and matches &#39;0&#39;, &#39;1&#39;, any alphabetic character, and the percent sign.</p>

<p>Perl recognizes the following POSIX character classes:</p>

<pre><code class="plaintext">alpha  Any alphabetical character (e.g., [A-Za-z]).
alnum  Any alphanumeric character (e.g., [A-Za-z0-9]).
ascii  Any character in the ASCII character set.
blank  A GNU extension, equal to a space or a horizontal tab (&quot;\t&quot;).
cntrl  Any control character.  See Note [2] below.
digit  Any decimal digit (e.g., [0-9]), equivalent to &quot;\d&quot;.
graph  Any printable character, excluding a space.  See Note [3] below.
lower  Any lowercase character (e.g., [a-z]).
print  Any printable character, including a space.  See Note [4] below.
punct  Any graphical character excluding &quot;word&quot; characters.  Note [5].
space  Any whitespace character. &quot;\s&quot; including the vertical tab
       (&quot;\cK&quot;).
upper  Any uppercase character (e.g., [A-Z]).
word   A Perl extension (e.g., [A-Za-z0-9_]), equivalent to &quot;\w&quot;.
xdigit Any hexadecimal digit (e.g., [0-9a-fA-F]).  Note [7].</code></pre>

<p>Like the <a href="perlrecharclass.html#Unicode-Properties">Unicode properties</a>, most of the POSIX properties match the same regardless of whether case-insensitive (<code>/i</code>) matching is in effect or not. The two exceptions are <code>[:upper:]</code> and <code>[:lower:]</code>. Under <code>/i</code>, they each match the union of <code>[:upper:]</code> and <code>[:lower:]</code>.</p>

<p>Most POSIX character classes have two Unicode-style <code>\p</code> property counterparts. (They are not official Unicode properties, but Perl extensions derived from official Unicode properties.) The table below shows the relation between POSIX character classes and these counterparts.</p>

<p>One counterpart, in the column labelled &quot;ASCII-range Unicode&quot; in the table, matches only characters in the ASCII character set.</p>

<p>The other counterpart, in the column labelled &quot;Full-range Unicode&quot;, matches any appropriate characters in the full Unicode character set. For example, <code>\p{Alpha}</code> matches not just the ASCII alphabetic characters, but any character in the entire Unicode character set considered alphabetic. An entry in the column labelled &quot;backslash sequence&quot; is a (short) equivalent.</p>

<pre><code class="plaintext">[[:...:]]      ASCII-range          Full-range  backslash  Note
                Unicode              Unicode     sequence
-----------------------------------------------------
  alpha      \p{PosixAlpha}       \p{XPosixAlpha}
  alnum      \p{PosixAlnum}       \p{XPosixAlnum}
  ascii      \p{ASCII}
  blank      \p{PosixBlank}       \p{XPosixBlank}  \h      [1]
                                  or \p{HorizSpace}        [1]
  cntrl      \p{PosixCntrl}       \p{XPosixCntrl}          [2]
  digit      \p{PosixDigit}       \p{XPosixDigit}  \d
  graph      \p{PosixGraph}       \p{XPosixGraph}          [3]
  lower      \p{PosixLower}       \p{XPosixLower}
  print      \p{PosixPrint}       \p{XPosixPrint}          [4]
  punct      \p{PosixPunct}       \p{XPosixPunct}          [5]
             \p{PerlSpace}        \p{XPerlSpace}   \s      [6]
  space      \p{PosixSpace}       \p{XPosixSpace}          [6]
  upper      \p{PosixUpper}       \p{XPosixUpper}
  word       \p{PosixWord}        \p{XPosixWord}   \w
  xdigit     \p{PosixXDigit}      \p{XPosixXDigit}         [7]</code></pre>

<dl>

<dt id="[1]1"><a class="permalink" href="perlrecharclass.html#%5B1%5D1">#</a><a id="pod-11"></a>[1]</dt>
<dd>

<p><code>\p{Blank}</code> and <code>\p{HorizSpace}</code> are synonyms.</p>

</dd>
<dt id="[2]1"><a class="permalink" href="perlrecharclass.html#%5B2%5D1">#</a><a id="pod-21"></a>[2]</dt>
<dd>

<p>Control characters don&#39;t produce output as such, but instead usually control the terminal somehow: for example, newline and backspace are control characters. On ASCII platforms, in the ASCII range, characters whose code points are between 0 and 31 inclusive, plus 127 (<code>DEL</code>) are control characters; on EBCDIC platforms, their counterparts are control characters.</p>

</dd>
<dt id="[3]"><a class="permalink" href="perlrecharclass.html#%5B3%5D">#</a><a id="pod-3"></a>[3]</dt>
<dd>

<p>Any character that is <i>graphical</i>, that is, visible. This class consists of all alphanumeric characters and all punctuation characters.</p>

</dd>
<dt id="[4]"><a class="permalink" href="perlrecharclass.html#%5B4%5D">#</a><a id="pod-4"></a>[4]</dt>
<dd>

<p>All printable characters, which is the set of all graphical characters plus those whitespace characters which are not also controls.</p>

</dd>
<dt id="[5]"><a class="permalink" href="perlrecharclass.html#%5B5%5D">#</a><a id="pod-5"></a>[5]</dt>
<dd>

<p><code>\p{PosixPunct}</code> and <code>[[:punct:]]</code> in the ASCII range match all non-controls, non-alphanumeric, non-space characters: <code>[-!&quot;#$%&amp;&#39;()*+,./:;&lt;=&gt;?@[\\\]^_`{|}~]</code> (although if a locale is in effect, it could alter the behavior of <code>[[:punct:]]</code>).</p>

<p>The similarly named property, <code>\p{Punct}</code>, matches a somewhat different set in the ASCII range, namely <code>[-!&quot;#%&amp;&#39;()*,./:;?@[\\\]_{}]</code>. That is, it is missing the nine characters <code>[$+&lt;=&gt;^`|~]</code>. This is because Unicode splits what POSIX considers to be punctuation into two categories, Punctuation and Symbols.</p>

<p><code>\p{XPosixPunct}</code> and (under Unicode rules) <code>[[:punct:]]</code>, match what <code>\p{PosixPunct}</code> matches in the ASCII range, plus what <code>\p{Punct}</code> matches. This is different than strictly matching according to <code>\p{Punct}</code>. Another way to say it is that if Unicode rules are in effect, <code>[[:punct:]]</code> matches all characters that Unicode considers punctuation, plus all ASCII-range characters that Unicode considers symbols.</p>

</dd>
<dt id="[6]"><a class="permalink" href="perlrecharclass.html#%5B6%5D">#</a><a id="pod-6"></a>[6]</dt>
<dd>

<p><code>\p{XPerlSpace}</code> and <code>\p{Space}</code> match identically starting with Perl v5.18. In earlier versions, these differ only in that in non-locale matching, <code>\p{XPerlSpace}</code> did not match the vertical tab, <code>\cK</code>. Same for the two ASCII-only range forms.</p>

</dd>
<dt id="[7]"><a class="permalink" href="perlrecharclass.html#%5B7%5D">#</a><a id="pod-7"></a>[7]</dt>
<dd>

<p>Unlike <code>[[:digit:]]</code> which matches digits in many writing systems, such as Thai and Devanagari, there are currently only two sets of hexadecimal digits, and it is unlikely that more will be added. This is because you not only need the ten digits, but also the six <code>[A-F]</code> (and <code>[a-f]</code>) to correspond. That means only the Latin script is suitable for these, and Unicode has only two sets of these, the familiar ASCII set, and the fullwidth forms starting at U+FF10 (FULLWIDTH DIGIT ZERO).</p>

</dd>
</dl>

<p>There are various other synonyms that can be used besides the names listed in the table. For example, <code>\p{XPosixAlpha}</code> can be written as <code>\p{Alpha}</code>. All are listed in <a href="perluniprops.html#Properties-accessible-through-%5Cp%7B%7D-and-%5CP%7B%7D">&quot;Properties accessible through \p{} and \P{}&quot; in perluniprops</a>.</p>

<p>Both the <code>\p</code> counterparts always assume Unicode rules are in effect. On ASCII platforms, this means they assume that the code points from 128 to 255 are Latin-1, and that means that using them under locale rules is unwise unless the locale is guaranteed to be Latin-1 or UTF-8. In contrast, the POSIX character classes are useful under locale rules. They are affected by the actual rules in effect, as follows:</p>

<dl>

<dt id="If-the-/a-modifier,-is-in-effect-..."><a class="permalink" href="perlrecharclass.html#If-the-/a-modifier,-is-in-effect-...">#</a><a id="If2"></a><a id="If-the-a-modifier-is-in-effect2"></a>If the <code>/a</code> modifier, is in effect ...</dt>
<dd>

<p>Each of the POSIX classes matches exactly the same as their ASCII-range counterparts.</p>

</dd>
<dt id="otherwise-...4"><a class="permalink" href="perlrecharclass.html#otherwise-...4">#</a><a id="otherwise4"></a>otherwise ...</dt>
<dd>

<dl>

<dt id="For-code-points-above-255-...2"><a class="permalink" href="perlrecharclass.html#For-code-points-above-255-...2">#</a><a id="For4"></a><a id="For-code-points-above-2552"></a>For code points above 255 ...</dt>
<dd>

<p>The POSIX class matches the same as its Full-range counterpart.</p>

</dd>
<dt id="For-code-points-below-256-...2"><a class="permalink" href="perlrecharclass.html#For-code-points-below-256-...2">#</a><a id="For5"></a><a id="For-code-points-below-2562"></a>For code points below 256 ...</dt>
<dd>

<dl>

<dt id="if-locale-rules-are-in-effect-...2"><a class="permalink" href="perlrecharclass.html#if-locale-rules-are-in-effect-...2">#</a><a id="if4"></a><a id="if-locale-rules-are-in-effect2"></a>if locale rules are in effect ...</dt>
<dd>

<p>The POSIX class matches according to the locale, except:</p>

<dl>

<dt id="word"><a class="permalink" href="perlrecharclass.html#word">#</a><code>word</code></dt>
<dd>

<p>also includes the platform&#39;s native underscore character, no matter what the locale is.</p>

</dd>
<dt id="ascii"><a class="permalink" href="perlrecharclass.html#ascii">#</a><code>ascii</code></dt>
<dd>

<p>on platforms that don&#39;t have the POSIX <code>ascii</code> extension, this matches just the platform&#39;s native ASCII-range characters.</p>

</dd>
<dt id="blank"><a class="permalink" href="perlrecharclass.html#blank">#</a><code>blank</code></dt>
<dd>

<p>on platforms that don&#39;t have the POSIX <code>blank</code> extension, this matches just the platform&#39;s native tab and space characters.</p>

</dd>
</dl>

</dd>
<dt id="if,-instead,-Unicode-rules-are-in-effect-...2"><a class="permalink" href="perlrecharclass.html#if,-instead,-Unicode-rules-are-in-effect-...2">#</a><a id="if5"></a><a id="if-instead-Unicode-rules-are-in-effect2"></a>if, instead, Unicode rules are in effect ...</dt>
<dd>

<p>The POSIX class matches the same as the Full-range counterpart.</p>

</dd>
<dt id="otherwise-...5"><a class="permalink" href="perlrecharclass.html#otherwise-...5">#</a><a id="otherwise5"></a>otherwise ...</dt>
<dd>

<p>The POSIX class matches the same as the ASCII range counterpart.</p>

</dd>
</dl>

</dd>
</dl>

</dd>
</dl>

<p>Which rules apply are determined as described in <a href="perlre.html#Which-character-set-modifier-is-in-effect%3F">&quot;Which character set modifier is in effect?&quot; in perlre</a>.</p>

<h4 id="Negation-of-POSIX-character-classes"><a class="permalink" href="perlrecharclass.html#Negation-of-POSIX-character-classes">#</a><a id="Negation1"></a>Negation of POSIX character classes </h4>

<p>A Perl extension to the POSIX character class is the ability to negate it. This is done by prefixing the class name with a caret (<code>^</code>). Some examples:</p>

<pre><code class="plaintext">    POSIX         ASCII-range     Full-range  backslash
                   Unicode         Unicode    sequence
-----------------------------------------------------
[[:^digit:]]   \P{PosixDigit}  \P{XPosixDigit}   \D
[[:^space:]]   \P{PosixSpace}  \P{XPosixSpace}
               \P{PerlSpace}   \P{XPerlSpace}    \S
[[:^word:]]    \P{PerlWord}    \P{XPosixWord}    \W</code></pre>

<p>The backslash sequence can mean either ASCII- or Full-range Unicode, depending on various factors as described in <a href="perlre.html#Which-character-set-modifier-is-in-effect%3F">&quot;Which character set modifier is in effect?&quot; in perlre</a>.</p>

<h4 id="[=-=]-and-[.-.]"><a class="permalink" href="perlrecharclass.html#%5B=-=%5D-and-%5B.-.%5D">#</a><a id="and"></a>[= =] and [. .]</h4>

<p>Perl recognizes the POSIX character classes <code>[=class=]</code> and <code>[.class.]</code>, but does not (yet?) support them. Any attempt to use either construct raises an exception.</p>

<h4 id="Examples1"><a class="permalink" href="perlrecharclass.html#Examples1">#</a>Examples</h4>

<pre><code class="plaintext">/[[:digit:]]/            # Matches a character that is a digit.
/[01[:lower:]]/          # Matches a character that is either a
                         # lowercase letter, or &#39;0&#39; or &#39;1&#39;.
/[[:digit:][:^xdigit:]]/ # Matches a character that can be anything
                         # except the letters &#39;a&#39; to &#39;f&#39; and &#39;A&#39; to
                         # &#39;F&#39;.  This is because the main character
                         # class is composed of two POSIX character
                         # classes that are ORed together, one that
                         # matches any digit, and the other that
                         # matches anything that isn&#39;t a hex digit.
                         # The OR adds the digits, leaving only the
                         # letters &#39;a&#39; to &#39;f&#39; and &#39;A&#39; to &#39;F&#39; excluded.</code></pre>

<h3 id="Extended-Bracketed-Character-Classes"><a class="permalink" href="perlrecharclass.html#Extended-Bracketed-Character-Classes">#</a><a id="Extended"></a>Extended Bracketed Character Classes  </h3>

<p>This is a fancy bracketed character class that can be used for more readable and less error-prone classes, and to perform set operations, such as intersection. An example is</p>

<pre><code class="plaintext">/(?[ \p{Thai} &amp; \p{Digit} ])/</code></pre>

<p>This will match all the digit characters that are in the Thai script.</p>

<p>This is an experimental feature available starting in 5.18, and is subject to change as we gain field experience with it. Any attempt to use it will raise a warning, unless disabled via</p>

<pre><code>no warnings &quot;experimental::regex_sets&quot;;</code></pre>

<p>Comments on this feature are welcome; send email to <code>perl5-porters@perl.org</code>.</p>

<p>The rules used by <a href="re.html#%27strict%27-mode"><code>use re &#39;strict</code></a> apply to this construct.</p>

<p>We can extend the example above:</p>

<pre><code class="plaintext">/(?[ ( \p{Thai} + \p{Lao} ) &amp; \p{Digit} ])/</code></pre>

<p>This matches digits that are in either the Thai or Laotian scripts.</p>

<p>Notice the white space in these examples. This construct always has the <code>/xx</code> modifier turned on within it.</p>

<p>The available binary operators are:</p>

<pre><code class="plaintext">&amp;    intersection
+    union
|    another name for &#39;+&#39;, hence means union
-    subtraction (the result matches the set consisting of those
     code points matched by the first operand, excluding any that
     are also matched by the second operand)
^    symmetric difference (the union minus the intersection).  This
     is like an exclusive or, in that the result is the set of code
     points that are matched by either, but not both, of the
     operands.</code></pre>

<p>There is one unary operator:</p>

<pre><code class="plaintext">!    complement</code></pre>

<p>All the binary operators left associate; <code>&quot;&amp;&quot;</code> is higher precedence than the others, which all have equal precedence. The unary operator right associates, and has highest precedence. Thus this follows the normal Perl precedence rules for logical operators. Use parentheses to override the default precedence and associativity.</p>

<p>The main restriction is that everything is a metacharacter. Thus, you cannot refer to single characters by doing something like this:</p>

<pre><code class="plaintext">/(?[ a + b ])/ # Syntax error!</code></pre>

<p>The easiest way to specify an individual typable character is to enclose it in brackets:</p>

<pre><code class="plaintext">/(?[ [a] + [b] ])/</code></pre>

<p>(This is the same thing as <code>[ab]</code>.) You could also have said the equivalent:</p>

<pre><code class="plaintext">/(?[[ a b ]])/</code></pre>

<p>(You can, of course, specify single characters by using, <code>\x{...}</code>, <code>\N{...}</code>, etc.)</p>

<p>This last example shows the use of this construct to specify an ordinary bracketed character class without additional set operations. Note the white space within it. This is allowed because <code>/xx</code> is automatically turned on within this construct.</p>

<p>All the other escapes accepted by normal bracketed character classes are accepted here as well.</p>

<p>Because this construct compiles under <a href="re.html#%27strict%27-mode"><code>use re &#39;strict</code></a>, unrecognized escapes that generate warnings in normal classes are fatal errors here, as well as all other warnings from these class elements, as well as some practices that don&#39;t currently warn outside <code>re &#39;strict&#39;</code>. For example you cannot say</p>

<pre><code class="plaintext">/(?[ [ \xF ] ])/     # Syntax error!</code></pre>

<p>You have to have two hex digits after a braceless <code>\x</code> (use a leading zero to make two). These restrictions are to lower the incidence of typos causing the class to not match what you thought it would.</p>

<p>If a regular bracketed character class contains a <code>\p{}</code> or <code>\P{}</code> and is matched against a non-Unicode code point, a warning may be raised, as the result is not Unicode-defined. No such warning will come when using this extended form.</p>

<p>The final difference between regular bracketed character classes and these, is that it is not possible to get these to match a multi-character fold. Thus,</p>

<pre><code class="plaintext">/(?[ [\xDF] ])/iu</code></pre>

<p>does not match the string <code>ss</code>.</p>

<p>You don&#39;t have to enclose POSIX class names inside double brackets, hence both of the following work:</p>

<pre><code class="plaintext">/(?[ [:word:] - [:lower:] ])/
/(?[ [[:word:]] - [[:lower:]] ])/</code></pre>

<p>Any contained POSIX character classes, including things like <code>\w</code> and <code>\D</code> respect the <code>/a</code> (and <code>/aa</code>) modifiers.</p>

<p>Note that <code>(?[ ])</code> is a regex-compile-time construct. Any attempt to use something which isn&#39;t knowable at the time the containing regular expression is compiled is a fatal error. In practice, this means just three limitations:</p>

<ol>

<li><p>When compiled within the scope of <code>use locale</code> (or the <code>/l</code> regex modifier), this construct assumes that the execution-time locale will be a UTF-8 one, and the generated pattern always uses Unicode rules. What gets matched or not thus isn&#39;t dependent on the actual runtime locale, so tainting is not enabled. But a <code>locale</code> category warning is raised if the runtime locale turns out to not be UTF-8.</p>

</li>
<li><p>Any <a href="perlunicode.html#User-Defined-Character-Properties">user-defined property</a> used must be already defined by the time the regular expression is compiled (but note that this construct can be used instead of such properties).</p>

</li>
<li><p>A regular expression that otherwise would compile using <code>/d</code> rules, and which uses this construct will instead use <code>/u</code>. Thus this construct tells Perl that you don&#39;t want <code>/d</code> rules for the entire regular expression containing it.</p>

</li>
</ol>

<p>Note that skipping white space applies only to the interior of this construct. There must not be any space between any of the characters that form the initial <code>(?[</code>. Nor may there be space between the closing <code>])</code> characters.</p>

<p>Just as in all regular expressions, the pattern can be built up by including variables that are interpolated at regex compilation time. But its best to compile each sub-component.</p>

<pre><code>my $thai_or_lao = qr/(?[ \p{Thai} + \p{Lao} ])/;
my $lower = qr/(?[ \p{Lower} + \p{Digit} ])/;</code></pre>

<p>When these are embedded in another pattern, what they match does not change, regardless of parenthesization or what modifiers are in effect in that outer pattern. If you fail to compile the subcomponents, you can get some nasty surprises. For example:</p>

<pre><code>my $thai_or_lao = &#39;\p{Thai} + \p{Lao}&#39;;
...
qr/(?[ \p{Digit} &amp; $thai_or_lao ])/;</code></pre>

<p>compiles to</p>

<pre><code>qr/(?[ \p{Digit} &amp; \p{Thai} + \p{Lao} ])/;</code></pre>

<p>But this does not have the effect that someone reading the source code would likely expect, as the intersection applies just to <code>\p{Thai}</code>, excluding the Laotian. Its best to compile the subcomponents, but you could also parenthesize the component pieces:</p>

<pre><code>my $thai_or_lao = &#39;( \p{Thai} + \p{Lao} )&#39;;</code></pre>

<p>But any modifiers will still apply to all the components:</p>

<pre><code>my $lower = &#39;\p{Lower} + \p{Digit}&#39;;
qr/(?[ \p{Greek} &amp; $lower ])/i;</code></pre>

<p>matches upper case things. So just, compile the subcomponents, as illustrated above.</p>

<p>Due to the way that Perl parses things, your parentheses and brackets may need to be balanced, even including comments. If you run into any examples, please submit them to <a href="https://github.com/Perl/perl5/issues">https://github.com/Perl/perl5/issues</a>, so that we can have a concrete example for this man page.</p>

<p>We may change it so that things that remain legal uses in normal bracketed character classes might become illegal within this experimental construct. One proposal, for example, is to forbid adjacent uses of the same character, as in <code>(?[ [aa] ])</code>. The motivation for such a change is that this usage is likely a typo, as the second &quot;a&quot; adds nothing.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
